package com.xdb.sqlparser;

import com.xdb.sqlparser.command.XDBCommand;
import com.xdb.sqlparser.command.dml.delete.SimpleDeleteCommand;
import com.xdb.sqlparser.command.dml.insert.SimpleInsertCommand;
import com.xdb.sqlparser.command.dml.select.SimpleSelectCommand;
import com.xdb.sqlparser.command.dml.update.SimpleUpdateCommand;

public class XDBSQLParser {
	static XDBSQLParser INSTANCE = new XDBSQLParser();
	/**
	 * 将SQL字符串语句转换为抽象命令对象XDBCommand
	 * 
	 * @param sql
	 *            SQL字符串语句
	 * @return 抽象命令对象
	 */
	public XDBCommand parse(String sql) {
		String trimSql = sql.toLowerCase().trim();
		if (trimSql.startsWith("insert")) {
			return new SimpleInsertCommand();
		} else if (trimSql.startsWith("delete")) {
			return new SimpleDeleteCommand();
		} else if (trimSql.startsWith("update")) {
			return new SimpleUpdateCommand();
		} else if (trimSql.startsWith("select")) {
			return new SimpleSelectCommand();
		} else {
			return null;
		}
	}

	public static XDBSQLParser getInstance() {
		return INSTANCE;
	}
}
